<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Promise的链式调用</title>
	</head>
	<body>
		<!-- 
		 需求  
		 网络请求  aaa -> 自己处理10行
		 处理：aaa111 -> 自己处理10行
		 处理：aaa111222 -> 自己处理
		 -->
		<script type="text/javascript">
			new Promise ((resolve,reject) => {
				setTimeout(() => {
					resolve('aaa')
					reject('error message')
				},1000)
			}).then((res) => {
				console.log(res,'第一次处理10行')
				return new Promise((resolve) =>{
					resolve(res+'111')
				})
			}).then(res =>{
				console.log(res,'第二次处理10行')
				return new Promise(resolve => {
					resolve(res+'222')
				})
			}).then(res => {
				console.log('第三次处理')
			})
			//第二种写法 简写resolve方法
			new Promise ((resolve,reject) => {
				setTimeout(() => {
					resolve('aaa')
				},1000)
			}).then((res) => {
				console.log(res,'第一次处理10行')
				return res+'111'/* new Promise((resolve) =>{
					resolve(res+'111')
				}) */
			}).then(res =>{
				console.log(res,'第二次处理10行')
				return res+'222'/* new Promise(resolve => {
					resolve(res+'222')
				}) */
			}).then(res => {
				console.log('第三次处理')
			}).catch(err => {
				console.log(err)
			})
		</script>
	</body>
</html>
